package edu.gatech.asthma.activity;

import edu.gatech.asthma.R;
import edu.gatech.asthma.database.DBAdapter;
import edu.gatech.asthma.database.ProfileVO;
import edu.gatech.asthma.ui_support.HelpMenuHelper;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.Spinner;
import android.widget.TextView;

/**
 * First GUI screen for profile creation in the parent interface
 * Allows user to gender and birthday
 */
public class CreateProfileParentActivity extends Activity {

	DBAdapter database;
	int identifier = -1;
	
	@Override
    protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_patient_information1);
        
        Bundle extras = getIntent().getExtras();
        if (extras != null) {
        	identifier = extras.getInt("ID");
        }
        database = new DBAdapter(this);
        database.open();
        
        //Customize instructions to include child's name
        TextView instructions = (TextView) findViewById(R.id.profile_instructions);
        instructions.setText(getString(R.string.profile_parent_instructions)+" "+database.getProfile(identifier).getName()
        		+" "+getString(R.string.profile_parent_instructions2));
        
    	final Spinner profileGender = (Spinner)findViewById(R.id.profile_gender);
    	final DatePicker profileBirthday = (DatePicker)findViewById(R.id.profile_birthday);
        
        Button nextPage = (Button)findViewById(R.id.profile_parent_next);           
        nextPage.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
            	//TODO check all inputs before leaving page
                ProfileVO profile = database.getProfile(identifier);
            	profile.setGender(profileGender.getSelectedItemPosition());
            	profile.setBirthday((profileBirthday.getMonth()+1) 
            			+ "-" + profileBirthday.getDayOfMonth() + "-" + profileBirthday.getYear()); //note month index starts at zero
            	database.updateProfile(identifier,profile.getName(), profile.getGender(), profile.getBirthday(), profile.getWeight(), 
            			profile.getWeight_unit(), profile.getHeight(), profile.getHeight_unit(), profile.getEthnicity(),
            			profile.getBgColor(), profile.getTintColor(), profile.getAccentColor(), profile.getPic(), profile.getBest());
            	Intent i = new Intent(CreateProfileParentActivity.this, CreateProfileParent2Activity.class);
            	i.putExtra("ID", identifier);
            	CreateProfileParentActivity.this.startActivity(i);
            }
        });
    }
	
	@Override
	public void onBackPressed() {
		//do not allow the user to press back on this page
	}
	
	/**
	 * User clicked the help button on this screen
	 * @param v ImageView clicked
	 */
	public void helpButtonClicked(View v) {
		HelpMenuHelper.displayHelpMessage(this);
	}
}
